package com.ruoyi.labdata.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.labdata.domain.LabOrgThirdRelDict;
import com.ruoyi.labdata.service.ILabLogotypeService;
import com.ruoyi.labdata.service.ILabOrgThirdRelDictService;

/**
 * 实验室安全字典Controller
 * 
 * @author winner pan
 * @date 2022-02-06
 */
@RestController
@RequestMapping("/labdata/labdict")
public class LabOrgThirdRelDictController extends BaseController {
	@Autowired
	private ILabOrgThirdRelDictService labOrgThirdRelDictService;
	@Autowired
	private ILabLogotypeService labLogotypeService;

	/**
	 * 查询实验室安全字典列表
	 */
	@PreAuthorize("@ss.hasPermi('labdata:labdict:query')")
	@GetMapping("/list")
	public TableDataInfo list(LabOrgThirdRelDict labOrgThirdRelDict) {
		startPage();
		List<LabOrgThirdRelDict> list = labOrgThirdRelDictService.selectLabOrgThirdRelDictList(labOrgThirdRelDict);
		return getDataTable(list);
	}

	/**
	 * 导出实验室安全字典列表
	 */
	// @PreAuthorize("@ss.hasPermi('labdata:labdict:export')")
	/*
	 * @Log(title = "实验室安全字典", businessType = BusinessType.EXPORT)
	 * 
	 * @GetMapping("/export") public AjaxResult export(LabOrgThirdRelDict
	 * labOrgThirdRelDict) { List<LabOrgThirdRelDict> list =
	 * labOrgThirdRelDictService.selectLabOrgThirdRelDictList(labOrgThirdRelDict
	 * ); ExcelUtil<LabOrgThirdRelDict> util = new
	 * ExcelUtil<LabOrgThirdRelDict>(LabOrgThirdRelDict.class); return
	 * util.exportExcel(list, "labdict"); }
	 */

	/**
	 * 获取实验室安全字典详细信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:labdict:query')")
	@GetMapping(value = "/{dictRelId}")
	public AjaxResult getInfo(@PathVariable("dictRelId") Long dictRelId) {
		return AjaxResult.success(labOrgThirdRelDictService.selectLabOrgThirdRelDictById(dictRelId));
	}

	/**
	 * 获取实验室安全指定标签信息
	 */
	@PreAuthorize("@ss.hasPermi('labdata:labdict:query')")
	@GetMapping(value = "/logotype/{logoKind}")
	public AjaxResult getLogotypeList(@PathVariable("logoKind") Long logoKind) {
		return AjaxResult.success(labLogotypeService.selectLabLogotypeByKind(logoKind));
	}

	/**
	 * 新增实验室安全字典
	 */
	@PreAuthorize("@ss.hasPermi('labdata:labdict:edit')")
	@Log(title = "实验室安全字典", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody LabOrgThirdRelDict labOrgThirdRelDict) {
		return toAjax(labOrgThirdRelDictService.insertLabOrgThirdRelDict(labOrgThirdRelDict));
	}

	/**
	 * 修改实验室安全字典
	 */
	@PreAuthorize("@ss.hasPermi('labdata:labdict:edit')")
	@Log(title = "实验室安全字典", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody LabOrgThirdRelDict labOrgThirdRelDict) {
		return toAjax(labOrgThirdRelDictService.updateLabOrgThirdRelDict(labOrgThirdRelDict));
	}

	/**
	 * 删除实验室安全字典
	 */
	@PreAuthorize("@ss.hasPermi('labdata:labdict:edit')")
	@Log(title = "实验室安全字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dictRelIds}")
	public AjaxResult remove(@PathVariable Long[] dictRelIds) {
		return toAjax(labOrgThirdRelDictService.deleteLabOrgThirdRelDictByIds(dictRelIds));
	}
}
